#include <iostream>
#include <memory>
#include <string>

// 1. 抽象产品接口
class Product{
public:
    virtual void operation() = 0;
    virtual ~Product() = default;
};

// 2. 具体产品类
class ConcreteProductA : public Product{
public:
    void operation() override{
        std::cout << "ConcreteProductA operation" << std::endl;
    }
};

class ConcreteProductB : public Product{
public:
    void operation() override{
        std::cout << "ConcreteProductB operation" << std::endl;
    }
};

// 3. 工厂类
class SimpleFactory{
public:
    static std::unique_ptr<Product> createProduct(const std::string& type){
        if(type == "A") return std::make_unique<ConcreteProductA>();
        if(type == "B") return std::make_unique<ConcreteProductB>();
        throw std::invalid_argument("Invalid product type");
    }
};

// 使用示例
int main()
{
    auto productA = SimpleFactory::createProduct("A");
    auto productB = SimpleFactory::createProduct("B");

    productA->operation();
    productB->operation();

    return 0;
}